<?php
/**
 * Created by PhpStorm.
 * User: 戎大富
 * Date: 2019/4/26
 * Time: 11:33
 */
namespace app\admin\controller;
use think\Db;
class Sandian extends Base {
    public function index(){

//        $data = [
//            ['name'=> '海门', 'value'=> 200],
//            ['name'=> '鄂尔多斯', 'value'=> 212],
//            ['name'=> '招远', 'value'=> 212],
//            ['name'=> '舟山', 'value'=> 212],
//            ['name'=> '齐齐哈尔', 'value'=> 214]
//        ];
//        $data2 = [
//            '海门'=>[121.15,31.89],
//            '鄂尔多斯'=>[ 109.781327,39.608266],
//            '招远'=>[ 120.38,37.35],
//            '舟山'=>[ 122.207216,29.985295],
//            '齐齐哈尔'=>[ 123.97,47.33]
//        ];
        $dis = 0;
        $where = array();
//        $where['s_sta'] = 1;
        $where['s_lon'] = ['>',0];
        $where['s_sheng'] = ['>',0];
        $data = Db::table('up_shops')->alias('shop')
            ->join('up_area s','shop.s_shi = s.district_id')
            ->join('up_area q','shop.s_qu = q.district_id')
            ->where($where)
            ->group('s_sheng,s_shi,s_qu')
            ->field('concat(s.district,q.district) name,count(*) as value,s_lon,s_lat')
            ->select();
        $data2 = array();
        if($data){
            $dis = 1;
            foreach ($data as $k=>$v){
                $data2[$v['name']] = [$v['s_lon'],$v['s_lat']];
            }
        }
        $data = json_encode($data);
        $data2 = json_encode($data2);
        $this->assign('data',$data);
        $this->assign('data2',$data2);
        $this->assign('dis',$dis);
        return $this->fetch();
    }
    public function users(){

//        $data = [
//            ['name'=> '海门', 'value'=> 200],
//            ['name'=> '鄂尔多斯', 'value'=> 212],
//            ['name'=> '招远', 'value'=> 212],
//            ['name'=> '舟山', 'value'=> 212],
//            ['name'=> '齐齐哈尔', 'value'=> 214]
//        ];
//        $data2 = [
//            '海门'=>[121.15,31.89],
//            '鄂尔多斯'=>[ 109.781327,39.608266],
//            '招远'=>[ 120.38,37.35],
//            '舟山'=>[ 122.207216,29.985295],
//            '齐齐哈尔'=>[ 123.97,47.33]
//        ];
        $dis = 0;
        $where = array();
//        $where['s_sta'] = 1;
        $where['user_lat'] = ['>',0];
        $where['user_province'] = ['>',0];
        $data = Db::table('up_u_user')->alias('shop')
            ->join('up_area s','shop.user_province = s.district_id')
            ->join('up_area q','shop.user_district = q.district_id')
            ->where($where)
            ->group('user_province,user_city,user_district')
            ->field('concat(s.district,q.district) name,count(*) as value,user_lon,user_lat')
            ->select();
        $data2 = array();
        if($data){
            $dis = 1;
            foreach ($data as $k=>$v){
                $data2[$v['name']] = [$v['user_lon'],$v['user_lat']];
            }
        }
        $data = json_encode($data);
        $data2 = json_encode($data2);
        $this->assign('data',$data);
        $this->assign('data2',$data2);
        $this->assign('dis',$dis);
        return $this->fetch();
    }
}